<!DOCTYPE html>
<html>
<head lang="zn-ch">
    <meta charset="UTF-8"/>
    <!-- <meta name="renderer" content="webkit" /> -->
    <title>search显示</title>
</head>
<body>

<datalist id="ide">
    <?php
    require 'conn.php';
    //查询数据表中的数据
    $sql = "select Building,Classes from classes";
    $result = $con->query($sql);
    $a = array();
    while ($row = $result->fetch_assoc()) {
        $count = count($row);//不能在循环语句中，由于每次删除row数组长度都减小
        for ($i = 0; $i < $count; $i++) {
            unset($row[$i]);//删除冗余数据
        }
        array_push($a, $row);
    }


    $c = array();
    for ($i = 0; $i < count($a); $i++) {
        if ($a[$i]['Building'] == 'LC') {
            $a[$i]['Building'] = '立诚';
            $c[$i] = $a[$i]['Building'] . $a[$i]['Classes'];
        } elseif ($a[$i]['Building'] == 'ZM') {
            $a[$i]['Building'] = '知明';
            $c[$i] = $a[$i]['Building'] . $a[$i]['Classes'];
        } elseif ($a[$i]['Building'] == 'XD') {
            $a[$i]['Building'] = '笃行';
            $c[$i] = $a[$i]['Building'] . $a[$i]['Classes'];
        } elseif ($a[$i]['Building'] == 'ZG') {
            $a[$i]['Building'] = '致广';
            $c[$i] = $a[$i]['Building'] . $a[$i]['Classes'];
        }
    }
    // echo $c[0];
    // print_r($c);

    // $provinces=$c;
    $tmp = $_GET['q'];
    $tmp = urldecode($tmp);
    $val = array();
    $k = 0;
    if (strlen($tmp) > 0) {
        for ($i = 0; $i < count($c); $i++) {
            if (strpos($c[$i], $tmp) !== false) {
                //传递值给val
                $val[$k] = $c[$i];
                //下标增加
                $k = $k + 1;
            }

        }
        //遍历val数组
        for ($j = 0; $j < count($val); $j++) {
            echo "<option value=$val[$j]>";
            // echo $val[$j];
            // echo "<br>";
        }
    }
    ?>
</datalist>
</body>
</html>

